package com.example.ruiji.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.ruiji.Dto.DishDto;
import com.example.ruiji.common.Result;
import com.example.ruiji.entity.Dish;
import com.example.ruiji.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dish")
public class DishController {

    @Autowired
    private DishService dishService;

    @GetMapping("/page")
    public Result<Page<DishDto>> pageResult(Integer page, Integer pageSize, String name) {
        return dishService.Page(page, pageSize, name);
    }

    @PostMapping
    public Result<String> add(@RequestBody DishDto dishDto) {
        return dishService.add(dishDto);
    }

    @GetMapping("/{id}")
    public Result<DishDto> getById(@PathVariable Long id) {
        return dishService.getById(id);
    }

    @PutMapping
    public Result<String> update(@RequestBody DishDto dishDto) {
        return dishService.update(dishDto);
    }

    @GetMapping("/list")
    public Result<List<DishDto>> list(Dish dish) {
        return dishService.list(dish);
    }
}
